<template>
  <view class="chat-header">
    <view class="header-left">
      <!-- 黄小西LOGO -->
      <view class="logo-container">
        <image src="/static/images/logo-huangxiaoxi.png" mode="aspectFit" class="logo-image"></image>
      </view>
    </view>
    <view class="header-center">
      <view class="title-container">
        <text class="header-title">{{title}}</text>
        <view class="voice-icon" @tap="toggleSpeaker">
          <image 
            			:src="speakerEnabled ? 'https://i.ibb.co/3Ykk4nJ6/voice-playing.png' : 'https://i.ibb.co/VWScjzHV/voice-play.png'" 
            mode="aspectFit"
            :class="['icon-image', isVoicePlaying ? 'icon-playing' : '']"
          ></image>
        </view>
      </view>
      <text class="header-subtitle">{{subtitle}}</text>
    </view>
    <view class="header-right">
      <!-- cunbb.png 篮球吉祥物头像 -->
      <view class="avatar-container">
        <image src="https://cdn.xryai.cn/picGo/20250907201408537.png" mode="aspectFit" class="avatar-image"></image>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'ChatHeader',
  props: {
    title: {
      type: String,
      default: '新如影'
    },
    subtitle: {
      type: String,
      default: 'xryai.cn'
    },
    speakerEnabled: {
      type: Boolean,
      default: false
    },
    isVoicePlaying: {
      type: Boolean,
      default: false
    },
  },
  methods: {
    goBack() {
      this.$emit('go-back');
    },
    toggleSpeaker() {
      this.$emit('toggle-speaker');
    },
    openHeaderMenu() {
      this.$emit('open-header-menu');
    },
  }
}
</script>

<style>
.chat-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  height: 80px;
  padding-top: var(--status-bar-height);
  border-bottom-left-radius: 16px;
  border-bottom-right-radius: 16px;
  backdrop-filter: blur(10px);
}

.header-left {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  width: 80px;
  margin-top: 10px;
}

.logo-container {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;
}

.logo-container:active {
  transform: scale(0.95);
}

.logo-image {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.header-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-back, .icon-image {
  width: 24px;
  height: 24px;
}

.back-icon {
  padding: 6px;
  margin-top: 10px;

}

.header-center {
  flex: 1;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  margin: 0 20px;
}

.title-container {
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-title {
  font-size: 22px;
  font-weight: bold;
  color: #222;
  text-align: center;
  margin-right: 8px;
  margin-top: 30px;

}

.voice-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 25px;
}

.icon-playing {
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.2);
    opacity: 0.8;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.header-subtitle {
  font-size: 13px;
  color: #999;
  margin-top: 0px;
}

.header-right {
  width: 80px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-top: 10px;
}

.avatar-container {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 20px;
  background: linear-gradient(135deg, #ff9800, #ff5722);
  box-shadow: 0 3px 10px rgba(255, 152, 0, 0.4);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.avatar-container:active {
  transform: scale(0.95);
  box-shadow: 0 2px 6px rgba(255, 152, 0, 0.3);
}

.avatar-image {
  width: 32px;
  height: 32px;
  border-radius: 16px;
}
</style>

<style>
/* 添加聊天框上边距，避免被导航栏遮挡 */
page {
  --chat-header-height: calc(80px + var(--status-bar-height));
}

/* 聊天内容容器样式，确保不被导航栏遮挡 */
.chat-container {
  padding-top: var(--chat-header-height);
}
</style> 